package hn.cch.grammar.java;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class CollectionsDemo {

    private final static Logger logger = LoggerFactory.getLogger(CollectionsDemo.class);

    @Test
    public void testEmpty() {
        List<String> list = Collections.emptyList();
    }


    @Test
    public void testSingleton() {
        List<String> list = Collections.singletonList("singleton");
    }

    @Test
    public void testSynchronized() {
        List<String> list = new ArrayList<>(Arrays.asList("item0", "item1", "item2"));
        List<String> synchronizedList = Collections.synchronizedList(list);
        synchronized (synchronizedList) {
            for (String item : synchronizedList) {
                logger.info("item:{}", item);
            }
        }
        synchronizedList.add("item3");
    }

    @Test
    public void test() {
        List<String> list = new ArrayList<>(Arrays.asList("item0", "item1", "item2"));
        List<String> unmodifiableList = Collections.unmodifiableList(list);
        // unmodifiableList.add("item3");
    }
}
